<HTML> 
<HEAD> 
	<TITLE>3rd Party ROBOTC Drivers</TITLE> 
<link href="tabs.css" rel="stylesheet" type="text/css"/> 
<link href="doxygen.css" rel="stylesheet" type="text/css"/> 
</HEAD> 
 
<BODY bgcolor="#ffffff" link="#000000" vlink="#000000"> 
<table width="100%" bgcolor="navy" cellspacing=0 cellpadding=1 border=0> 
<tr><td><table width="100%" bgcolor="#EEEEDD" cellspacing=0 cellpadding=3 border=0> 
<tr> 
    <td width="33%" align="left"> <img src="images/LOGO_NXT.gif" width=266 height=44 border="0" alt="Mindstorms"></td> 
    <td><b><font size="+3" color="navy">3rd Party ROBOTC Drivers</font></b></td> 
    <td align="right"> <img src="images/logo.png" width=44 height=44 border="0" alt="RobotC"></td>     
</tr> 
  <tr bgcolor="#cccc99" align="right"> 
          <td colspan=3> <font face="arial" size="-1"> [<a href=main.html>Home</a>] [<a target=_top href="https://sourceforge.net/projects/rdpartyrobotcdr/">Download</a>] [<a target=_top href="http://apps.sourceforge.net/mantisbt/rdpartyrobotcdr/my_view_page.php">Submit a bug/suggestion</a>]  [<a target=_top href="http://www.robotc.net/forums/">ROBOTC Forums</a>] [<a target=_top href="http://botbench.com">Blog</a>] [<a target=_top href="http://sourceforge.net/donate/index.php?group_id=257238">Support this project</a>]</font> </td> 
</tr> 
</table></td></tr> 
</table> 
<!-- Generated by Doxygen 1.7.2 -->
<div class="header">
  <div class="headertitle">
<h1>dexterind-imu-test1.c</h1>  </div>
</div>
<div class="contents">
<div class="fragment"><pre class="fragment"><span class="preprocessor">#pragma config(Sensor, S1,     DIMU,                sensorI2CCustomFastSkipStates)</span>
<span class="preprocessor"></span><span class="comment">//*!!Code automatically generated by &#39;ROBOTC&#39; configuration wizard               !!*//</span>

<span class="comment">/*</span>
<span class="comment"> * $Id: dexterind-imu-test1.c 133 2013-03-10 15:15:38Z xander $</span>
<span class="comment"> */</span>
<span class="comment"></span>
<span class="comment">/**</span>
<span class="comment"> * dexterind-imu.h provides an API for the Dexter Industries IMU Sensor.  This program</span>
<span class="comment"> * demonstrates how to use that API.</span>
<span class="comment"> *</span>
<span class="comment"> * Changelog:</span>
<span class="comment"> * - 0.1: Initial release</span>
<span class="comment"> *</span>
<span class="comment"> * Credits:</span>
<span class="comment"> * - Big thanks to Dexter Industries for providing me with the hardware necessary to write and test this.</span>
<span class="comment"> *</span>
<span class="comment"> * License: You may use this code as you wish, provided you give credit where it&#39;s due.</span>
<span class="comment"> *</span>
<span class="comment"> * THIS CODE WILL ONLY WORK WITH ROBOTC VERSION 3.59 AND HIGHER. </span>
<span class="comment"></span>
<span class="comment"> * Xander Soldaat (xander_at_botbench.com)</span>
<span class="comment"> * 07 August 2011</span>
<span class="comment"> * version 0.1</span>
<span class="comment"> */</span>

<span class="preprocessor">#include &quot;<a class="code" href="dexterind-imu_8h.html" title="Dexter Industries IMU Sensor driver.">drivers/dexterind-imu.h</a>&quot;</span>

task main(){

  <span class="keywordtype">float</span> x_val, y_val, z_val;      <span class="comment">// Gyro axis values</span>

  nxtDisplayCenteredTextLine(0, <span class="stringliteral">&quot;Dexter Ind.&quot;</span>);
  nxtDisplayCenteredBigTextLine(1, <span class="stringliteral">&quot;IMU&quot;</span>);
  nxtDisplayCenteredTextLine(3, <span class="stringliteral">&quot;Test 1&quot;</span>);
  nxtDisplayCenteredTextLine(5, <span class="stringliteral">&quot;Connect sensor&quot;</span>);
  nxtDisplayCenteredTextLine(6, <span class="stringliteral">&quot;to S1&quot;</span>);
  wait1Msec(2000);
  eraseDisplay();

  <span class="comment">// Fire up the gyro and initialize it. Only needs to be done once.</span>
  <span class="comment">//DIMUconfigGyro(DIMU, DIMU_GYRO_RANGE_500);</span>
  <span class="keywordflow">if</span> (!<a name="a0"></a><a class="code" href="group___d_i_m_u.html#gae23d7e3cdc85d3113a302cb094c2746c">DIMUconfigAccel</a>(DIMU, <a name="a1"></a><a class="code" href="group___d_i_m_u.html#ga301e1ce2d9909389cfc690077187f5df">DIMU_ACC_RANGE_2G</a>))
    PlaySound(soundException);

  <span class="keywordflow">if</span>(!<a name="a2"></a><a class="code" href="group___d_i_m_u.html#ga6e9ba4ee66fd46ccf2bc506870289034">DIMUconfigGyro</a>(DIMU, <a name="a3"></a><a class="code" href="group___d_i_m_u.html#ga37417ffca147e84baeb5233b6ebd6081">DIMU_GYRO_RANGE_500</a>))
    PlaySound(soundException);

  <span class="keywordflow">while</span> (<span class="keyword">true</span>){

                <span class="comment">// Read the GYROSCOPE</span>
    <span class="comment">// There are 3 ways to do this:</span>

    <span class="comment">// All at once, very convenient if you need all 3</span>
    <a name="a4"></a><a class="code" href="group___d_i_m_u.html#gab827ec900619ac00a404286787bd4374">DIMUreadGyroAxes</a>(DIMU, x_val, y_val, z_val);

    <span class="comment">// Via a single command with the axis specified as one of the arguments</span>
                <span class="comment">//x_val = DIMUreadGyroAxis(DIMU, DIMU_GYRO_X_AXIS);    // Get x-axis in dps.</span>
                <span class="comment">//y_val = DIMUreadGyroAxis(DIMU, DIMU_GYRO_Y_AXIS);    // Get y-axis in dps.</span>
                <span class="comment">//z_val = DIMUreadGyroAxis(DIMU, DIMU_GYRO_Z_AXIS);    // Get z-axis in dps.</span>

    <span class="comment">// Using a macro that calls the above function with the right argument</span>
    <span class="comment">// x_val = DIMUreadGyroXAxis(DIMU);    // Get x-axis in dps.</span>
                <span class="comment">// y_val = DIMUreadGyroYAxis(DIMU);    // Get y-axis in dps.</span>
                <span class="comment">// z_val = DIMUreadGyroZAxis(DIMU);    // Get z-axis in dps.</span>

                nxtDisplayTextLine(1, <span class="stringliteral">&quot;%f&quot;</span>, x_val);
                nxtDisplayTextLine(2, <span class="stringliteral">&quot;%f&quot;</span>, y_val);
                nxtDisplayTextLine(3, <span class="stringliteral">&quot;%f&quot;</span>, z_val);

                <span class="comment">// Read the accelerometer</span>
                <span class="comment">// Again, there are multiple ways to do this:</span>

                <span class="comment">// All at once, in either 8 bit or 10 bit format</span>
                <span class="comment">// DIMUreadAccelAxes8Bit(DIMU, x_val, y_val, z_val);</span>
                <span class="comment">// DIMUreadAccelAxes10Bit(DIMU, x_val, y_val, z_val);</span>

                <span class="comment">// One by one, specifying the axis as an argument, available in 8 and 10 bit.</span>
                <span class="comment">//</span>
                <span class="comment">// 8 bit</span>
                <span class="comment">//x_val = DIMUreadAccelAxis8Bit(DIMU, DIMU_ACC_X_AXIS);</span>
                <span class="comment">// y_val = DIMUreadAccelAxis8Bit(DIMU, DIMU_ACC_Y_AXIS);</span>
                <span class="comment">// z_val = DIMUreadAccelAxis8Bit(DIMU, DIMU_ACC_Z_AXIS);</span>
                <span class="comment">//</span>
                <span class="comment">// 10 bit</span>
                x_val = <a name="a5"></a><a class="code" href="group___d_i_m_u.html#ga5a776ba768845791ae8f4ebc68bb7f61">DIMUreadAccelAxis10Bit</a>(DIMU, <a name="a6"></a><a class="code" href="group___d_i_m_u.html#gaf85e1b013649f1a48dada5377dd37539">DIMU_ACC_X_AXIS</a>);
                y_val = <a class="code" href="group___d_i_m_u.html#ga5a776ba768845791ae8f4ebc68bb7f61">DIMUreadAccelAxis10Bit</a>(DIMU, <a name="a7"></a><a class="code" href="group___d_i_m_u.html#ga848aedcc8dccf9afaf4b4e122adcfdd1">DIMU_ACC_Y_AXIS</a>);
                z_val = <a class="code" href="group___d_i_m_u.html#ga5a776ba768845791ae8f4ebc68bb7f61">DIMUreadAccelAxis10Bit</a>(DIMU, <a name="a8"></a><a class="code" href="group___d_i_m_u.html#gaf1a0ef415e159c87a8a022ed1259e052">DIMU_ACC_Z_AXIS</a>);

                <span class="comment">// Function that doesn&#39;t require a specified axis, this is just a macro</span>
                <span class="comment">// x_val = DIMUreadAccelXAxis8Bit(DIMU);</span>
    <span class="comment">// y_val = DIMUreadAccelYAxis8Bit(DIMU);</span>
    <span class="comment">// z_val = DIMUreadAccelZAxis8Bit(DIMU);</span>

    <span class="comment">// x_val = DIMUreadAccelXAxis10Bit(DIMU);</span>
    <span class="comment">// y_val = DIMUreadAccelYAxis10Bit(DIMU);</span>
    <span class="comment">// z_val = DIMUreadAccelZAxis10Bit(DIMU);</span>

                nxtDisplayTextLine(5, <span class="stringliteral">&quot;%f&quot;</span>, x_val);
                nxtDisplayTextLine(6, <span class="stringliteral">&quot;%f&quot;</span>, y_val);
                nxtDisplayTextLine(7, <span class="stringliteral">&quot;%f&quot;</span>, z_val);
                wait1Msec(50);
  }
}

<span class="comment">/*</span>
<span class="comment"> * $Id: dexterind-imu-test1.c 133 2013-03-10 15:15:38Z xander $</span>
<span class="comment"> */</span>
</pre></div> </div>
</div>
<hr class="footer"/><address class="footer"><small>Generated on Wed Mar 13 2013 19:56:41 for ROBOTC Drivers by&#160;
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.2 </small></address>
</body>
</html>
